Skip to content

Mockgun: implement download_attachment - #470

Open
patrickwolf wants to merge 2 commits into
shotgunsoftware:masterfrom
patrickwolf:mockgun-download-attachment
Open

patrickwolf wants to merge 2 commits into
shotgunsoftware:masterfrom
patrickwolf:mockgun-download-attachment

Conversation

@patrickwolf

Copy link
Copy Markdown

Builds on the upload PR #469 (mockgun-upload); this diff shows only the download part.

Problem

Mockgun has no download_attachment, so code that downloads a movie or a file it uploaded cannot be tested on Mockgun.

Change

  • upload keeps a copy of the file in a temporary folder, made on the first upload and removed when the Mockgun instance is garbage-collected. The copy outlives the source file, as an upload does.
  • download_attachment(attachment, file_path=None, attachment_id=None) has the same signature as Shotgun.download_attachment and accepts the same arguments: an Attachment entity, a File/Link field value, or an Attachment id (also through the deprecated attachment_id).
  • It returns the file's bytes, or writes it to file_path and returns that path. It returns None for None.
  • A local file link (link_type: "local") returns the file at its local_path.
  • An attachment Mockgun has no file for raises ShotgunFileDownloadError, and a call without an attachment raises TypeError, as on the server.

Tests

TestDownloadAttachment: download by entity, field value, id and attachment_id, to bytes and to a path; the copy outlives the source; a local file link; missing attachments; the folder is removed with the instance.

python -m pytest tests/test_mockgun.py

Merge order

Merge after the upload PR #469 , then point this one at master. If the field types, default value types or limit and page PRs are merged first, this one needs a rebase that keeps their test classes next to its own at the end of tests/test_mockgun.py.

patrickwolf and others added 2 commits November 16, 2026 17:44
upload raised NotImplementedError. It now validates the path and the field as the server does and creates the records an upload leaves: an Attachment linked to the entity, holding the file's name, size and tags, and the File/Link field pointing at it. A thumbnail field sets the entity's image field. The file itself is not stored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
upload now keeps a copy of the file in a temporary folder, removed with the Mockgun instance. download_attachment returns it, as bytes or written to file_path, for an Attachment entity, a File/Link field value or an id, and also returns the file of a local file link. It raises ShotgunFileDownloadError for an attachment it has no file for, as the server does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@patrickwolf
patrickwolf force-pushed the mockgun-download-attachment branch from 97950b5 to 2563f0b Compare November 16, 2026 17:45

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant